package com.myy.auth.controller;

import com.myy.auth.service.FileService;
import com.myy.auth.vo.FileVo;
import com.myy.common.result.Result;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@AllArgsConstructor
@RestController
@RequestMapping("file")
public class FileController {
    private final FileService fileService;

    /**
     * 文件上传
     */
    @PostMapping("/upload")
    public Result<FileVo> uploadFile(@RequestParam("file") MultipartFile file) {
        return Result.success(fileService.uploadFile(file));
    }

    /**
     * 文件下载
     */
    @GetMapping("download")
    public void downloadFile(HttpServletResponse response, @RequestParam("id") String fileId) {
        fileService.downloadFile(response, fileId);
    }
}
